﻿ 
using Microsoft.Extensions.DependencyInjection;
using SSPivot.Common.Cache;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SSPivot.Common.Cache
{
    internal class demo
    {
        ////        // 初始化单例管理器
        ////        CacheManager.Initialize(new CacheConfig
        ////        {
        ////            Mode = CacheMode.Both,
        ////            RedisConnection = "localhost:6379"
        ////        });

        ////        // 使用单例访问
        ////        var cache = CacheManager.Instance;

        ////    // 基础使用
        ////    cache.Set("user:1001", new { Id = 1001, Name = "Alice" });
        ////var user = cache.Get<dynamic>("user:1001");
        ////Console.WriteLine($"User: {user?.Name}");

        ////// 使用Redis扩展功能
        ////if (cache.IsDistributedCacheEnabled)
        ////{
        ////    // Hash操作
        ////    var hashData = new Dictionary<string, object>
        ////    {
        ////        ["Age"] = 30,
        ////        ["Country"] = "US"
        ////    };
        ////    cache.RedisDatabase.HashSet("user:1001:meta", hashData);

        ////    // List操作
        ////    cache.RedisDatabase.ListPush("messages", "Hello");
        ////    cache.RedisDatabase.ListPush("messages", "World");

        ////    // Lua脚本
        ////    var luaResult = cache.RedisDatabase.ExecuteLuaScript(
        ////        "return {redis.call('GET', KEYS[1]), ARGV[1]}",
        ////        new RedisKey[] { "user:1001" },
        ////        "additional_param");

        ////    Console.WriteLine($"Lua result: {luaResult}");
        ////}

        ////// 依赖注入使用示例
        ////var serviceCollection = new ServiceCollection();
        ////serviceCollection.AddSingleton<ICacheService>(CacheManager.Instance);
        ////var serviceProvider = serviceCollection.BuildServiceProvider();

        ////var diCache = serviceProvider.GetService<ICacheService>();
        ////diCache.Set("config:timeout", 5000);
        ////Console.WriteLine($"Timeout: {diCache.Get<int>("config:timeout")}");
    }
}
